package com.example.toy.core.conf;

import com.example.toy.core.system.AbstractToySystem;
import lombok.SneakyThrows;

import java.util.Properties;

/**
 * SystemConfig
 *
 * @author shenbing
 * @date 2021/12/23
 */
public class ToySystemConfig extends SimpleConfig {
  public static final String FSOFFLINE_PATH_KEY = "toy.system.fsoffline.path";
  public static final String FSOFFLINE_SHORT_NAME = "fsoffline";
  public static final String FSOFFLINE_TYPE_NAME = "com.example.toy.FsOfflineToySystemImpl";

  public ToySystemConfig() {
    super(new Properties());
  }

  public String getSystemName() {
    return getString(ToyConfigs.TOY_SYSTEM_NAME.getKey());
  }

  @SneakyThrows
  public Class<? extends AbstractToySystem> getSystemType() {
    String type = getString(ToyConfigs.TOY_SYSTEM_TYPE.getKey());
    String className = type;
    if (FSOFFLINE_SHORT_NAME.equals(type)) {
      className = FSOFFLINE_TYPE_NAME;
    }
    return (Class<? extends AbstractToySystem>) Class.forName(className);
  }

}
